set(LUA_LIB_SRC
    lapi.c
    lcode.c
    lctype.c
    ldebug.c
    ldo.c
    ldump.c
    lfunc.c
    lgc.c
    llex.c
    lmem.c
    lobject.c
    lopcodes.c
    lparser.c
    lstate.c
    lstring.c
    ltable.c
    ltm.c
    lundump.c
    lvm.c
    lzio.c
    lauxlib.c
    lbaselib.c
    lcorolib.c
    ldblib.c
    liolib.c
    lmathlib.c
    loadlib.c
    loslib.c
    lstrlib.c
    ltablib.c
    lutf8lib.c
    linit.c
)


set(LUA_SRC
    lua.c
)

set(LUAC_SRC
    luac.c
)

add_library(lualib_static STATIC
    ${LUA_LIB_SRC}
)

target_include_directories(lualib_static
PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
)


add_library(lualib SHARED
    ${LUA_LIB_SRC}
)

if (CMAKE_SYSTEM_NAME MATCHES "Windows")
    target_compile_definitions(lualib
    PUBLIC
        LUA_BUILD_AS_DLL
    )
endif()

target_include_directories(lualib
PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
)

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    target_link_libraries(lualib
    PRIVATE
        dl
        m
    )
endif()

add_executable(lua
    ${LUA_SRC}
)

target_link_libraries(lua
PRIVATE
    lualib
)

add_executable(luac
    ${LUAC_SRC}
)

target_link_libraries(luac
PRIVATE
    lualib_static
)

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    target_link_libraries(luac
    PRIVATE
        dl
        m
    )
endif()